<?php

    class ProductType {

        public static function InsertProductType($producttype) {
            Connection::Connect();
            if($try = ProductType::ReadProductType($producttype) != NULL)
                return $try;

            $sql = mysql_query(
                "
                    INSERT INTO 
                    ProductType (
                        TypeName
                    ) 
                    VALUES (
                        '$producttype'
                    )
                "
            );

            if($sql == FALSE)
                return NULL;

            return $producttype;
        }

        public static function ReadProductType($producttypeid) {
            Connection::Connect();
            $sql = mysql_query(
                "
                    SELECT 
                        *
                    FROM 
                        ProductType 
                    WHERE
                        TypeName = '$producttypeid'
                "
            );

            if($sql == NULL)
                return NULL;

            $rows = mysql_num_rows($sql);
            if($rows == 1) {
                while($row = mysql_fetch_assoc($sql))
                {
                    $typename = $row['TypeName'];
                    return $typename;
                }
            }
            return NULL;
        }

        public static function UpdateProductType($oldtypename, $newtypename) {
            Connection::Connect();
            $sql = mysql_query(
                "
                    UPDATE 
                        ProductType 
                    SET 
                        TypeName = '$newtypename'
                    WHERE 
                        TypeName = '$oldtypename'
                " 
            );

            if($sql == FALSE)
                return NULL;

            return $newtypename;
        }

    }

?>